-- PreloadList
-- Create by weism
-- 配置在客户端启动后，需要预先加载的内容。这样在后续就可以避免大量的IO读取
-- 需要注意的是，预先加载时应该在比较闲空的页面（目前是准备开始游戏界面和登录界面）

-- 所有需要预先加载的，配置在此
local CMD = "game/cmd/";
local MODULE = "game/logic/module/";
local CSV = "game/csv/";
local PROP = "game/logic/module/prop/";
local FORMULA = "game/formula/";
local list = {
    { "scene", "game/scene/GameScene" },
    { "lua", CMD.."msg_login" },
    { "lua", CMD.."msg_start_game" },
    { "lua", CMD.."msg_me_updated" },
    { "module", "AttribM" },
    { "lua", CSV.."attrib_formula" },
    { "lua", CSV.."attrib_limit" },
    { "module", "ArtifactM" },
    { "lua", CSV.."artifact" },
    { "module", "EffectM" },
    { "module", "DesertAltarM" },
    { "lua", CSV.."desert_altar" },
    { "lua", CSV.."desert_altar_options" },
    { "module", "HolyItemsM" },
    { "lua", CSV.."holy_items" },
    { "module", "SpecialEquipM" },
    { "lua", CSV.."special_equip" },
    { "module", "SuitM" },
    { "lua", CSV.."suit" },
    { "lua", PROP.."skill_type_cost" },
    { "module", "FormulaM" },
    { "lua", FORMULA.."list" },
    { "lua", FORMULA.."IS_FOREVER_PROP" },
    { "module", "ElementMagicM" },
    { "lua", FORMULA.."CALC_FINAL_SKILL" },
    { "lua", MODULE.."skill/prop" },
    { "module", "CombatStatusM" },
    { "path", "game/logic/module/combat_status" },
    { "lua", CSV.."combat_status" },
    { "module", "LictorM" },
    { "module", "AlchemyWorkshopM" },
    { "module", "TimeM" },
    { "lua", CSV.."workshop_item" },
    { "lua", CSV.."workshop_guide" },
    { "lua", CSV.."workshop_strengthen_cost" },
    { "module", "SkyRelicFunctionM" },
    { "lua", CSV.."relic_function" },
    { "path", "game/logic/module/sky_relic_functions" },
    { "lua", "game/operation/cmd_get_server_time" },
    { "lua", CMD.."msg_items" },
    { "module", "SimpleEncryptM" },
    { "lua", CSV.."attrib_coding" },
    { "lua", CMD.."msg_pets" },
    { "module", "CareerM" },
    { "lua", CSV.."department" },
    { "lua", CMD.."msg_dungeon_progress" },
    { "lua", CMD.."msg_recharge_enabled" },
    { "module", "MarketM" },
    { "lua", CSV.."market" },
    { "lua", CSV.."limit_time_gift" },
    { "lua", CMD.."msg_taken_backup_bonus" },
    { "module", "TalentFruitBonusM" },
    { "lua", CSV.."talent_fruit_bonus" },
    { "lua", CMD.."msg_learned_career_stat" },
    { "lua", CMD.."msg_ss_backup_bonus" },
    { "lua", CMD.."msg_sky_army_data" },
    { "lua", CMD.."msg_dungeon_area" },
    { "lua", CMD.."msg_sign_in_data" },
    { "lua", CMD.."msg_ship_skills" },
    { "lua", CMD.."msg_notify_airship_is_new" },
    { "lua", CMD.."msg_notify_closed_area" },
    { "module", "NewAirShipM" },
    { "lua", CSV.."new_airship" },
    { "lua", CSV.."airship_deck" },
    { "lua", CSV.."airship_strengthen" },
    { "lua", CSV.."airship_material" },
    { "lua", CSV.."sky_city_guide" },
    { "lua", CMD.."msg_life_recovery_left_time" },
    { "lua", CMD.."msg_notify_main_map_top_info" },
    { "module", "TopM" },
    { "lua", CSV.."nationality" },
    { "lua", CMD.."msg_creation_gate_info" },
    { "lua", CMD.."msg_relic_func" },
    { "lua", CMD.."msg_market_buy_info" },
    { "lua", CMD.."msg_notify_server_status" },
    { "module", "ServerStatusM" },
    { "lua", CMD.."msg_scout_explore" },
    { "module", "ScoutM" },
    { "lua", CSV.."scout_explore" },
    { "lua", CMD.."msg_notify_buff_data" },
    { "module", "BuffDataM" },
    { "lua", CSV.."buff_data" },
    { "lua", CMD.."msg_black_market_info" },
    { "module", "BlackMarketM" },
    { "lua", CSV.."black_market_rule" },
    { "lua", CSV.."black_market_goods" },
    { "lua", CMD.."msg_notify_push_setting" },
    { "module", "PushM" },
    { "lua", CSV.."push" },
    { "lua", CMD.."msg_user_read_boards_record" },
    { "lua", CMD.."msg_user_boards" },
    { "lua", CMD.."msg_contact_enabled" },
    { "lua", CMD.."msg_notify_diary" },
    { "module", "ElementAltarM" },
    { "lua", CSV.."element" },
    { "lua", CSV.."element_lord" },
    { "lua", CSV.."element_altar" },
    { "lua", CMD.."msg_appeared_sky_instance" },
    { "lua", CMD.."msg_instance_class_stat" },
    { "module", "DungeonInstanceM" },
    { "lua", CSV.."dungeon_instance" },
    { "lua", MODULE.."dungeon_instance/list" },
    { "lua", MODULE.."dungeon_instance/rest_room" },
    { "lua", CMD.."msg_shop_info" },
    { "lua", CMD.."msg_combat_stat" },
    { "lua", CMD.."msg_dungeon_field_stat" },
    { "lua", CMD.."msg_workshop" },
    { "lua", CMD.."msg_workshop_strengthen" },
    { "lua", CMD.."msg_workshop_guide_progress" },
    { "module", "StatusM" },
    { "lua", CSV.."status" },
    { "lua", CMD.."msg_workshop_bonus" },
    { "module", "DragonWishM" },
    { "lua", CSV.."dragon_wish" },
    { "path", MODULE.."dragon_wish" },
    { "lua", FORMULA.."DRAGON_WISH_ITEM" },
    { "lua", FORMULA.."CALC_COMPOUND_MONEY" },
    { "lua", CMD.."msg_building_bonus_stat" },
    { "module", "BuildingBonusM" },
    { "lua", CSV.."building_view" },
    { "lua", CSV.."building_bonus_stat" },
    { "lua", CMD.."msg_training_room_info" },
    { "module", "TrainingM" },
    { "lua", CMD.."msg_eggs_info" },
    { "module", "EggsM" },
    { "lua", CSV.."eggs" },
    { "lua", CMD.."msg_artifact_durability" },
    { "lua", CMD.."msg_artifact_level" },
    { "lua", CMD.."msg_pet_shop_scrap_info" },
    { "module", "PetShopM" },
    { "lua", CSV.."pet_shop" },
    { "lua", CSV.."golden_pot_use_bonus" },
    { "lua", CMD.."msg_login_notify_ok" },
    { "module", "DungeonLogM" },
    { "module", "CombatM" },
    { "module", "AdM" },
    { "module", "SkyRelicM" },
    { "lua", CSV.."rob_relic_extra_bonus" },
    { "lua", CSV.."relic_boss" },
    { "lua", CSV.."relic_eggs" },
    { "path", MODULE.."dungeon_actions"},
    
    -- 常用的prop
    { "lua", PROP.."attrib2.lua" },
    { "lua", PROP.."attrib.lua" },
    { "lua", PROP.."combine_cost.lua" },
    { "lua", PROP.."divide_equip2.lua" },
    { "lua", PROP.."magic_effect.lua" },
    { "lua", PROP.."cost.lua" },
    { "lua", PROP.."special_level.lua" },
    { "lua", PROP.."fire_control.lua" },
    { "lua", PROP.."enter_roll_bonus.lua" },
    { "lua", PROP.."spell_bonus2.lua" },
    { "lua", PROP.."skill_level.lua" },
    { "lua", PROP.."career_bonus.lua" },
    { "lua", PROP.."cure_magic_skill.lua" },
    { "lua", PROP.."magic_effect_style.lua" },
    { "lua", PROP.."triple_spell.lua" },
    { "lua", PROP.."score.lua" },
    { "lua", PROP.."camp_dodge.lua" },
    { "lua", PROP.."camp_max_dodge.lua" },
    { "lua", PROP.."material_time.lua" },
    { "lua", PROP.."elect_add_attack.lua" },
    { "lua", PROP.."skill_goal_add.lua" },
    { "lua", PROP.."camp_attack.lua" },
    { "lua", PROP.."camp_max_hp.lua" },
    { "lua", PROP.."magic_revive.lua" },
    { "lua", PROP.."resur_spend.lua" },
    { "lua", PROP.."use_pot.lua" },
    { "lua", PROP.."mop_up.lua" },
    { "lua", PROP.."sky_attrib.lua" },
    { "lua", PROP.."skill_add_invincible.lua" },
    { "lua", PROP.."department_attack.lua" },
    { "lua", PROP.."department_max_hp.lua" },
    { "lua", PROP.."camp_defense.lua" },
    { "lua", PROP.."advance_time.lua" },
    { "lua", PROP.."add_grid_area.lua" },
    { "lua", PROP.."camp_learn_phy.lua" },
    { "lua", PROP.."material_down.lua" },
    { "lua", PROP.."all_clear.lua" },
    { "lua", PROP.."app_goods_num.lua" },
    { "lua", PROP.."app_black_market.lua" },
    { "lua", PROP.."scout_bonus.lua" },
    { "lua", PROP.."repair_cost.lua" },
    { "lua", PROP.."upgrade_cost.lua" },
    { "lua", PROP.."camp_ranged_damage.lua" },
    { "lua", PROP.."apprentice_slime.lua" },
    { "lua", PROP.."magic_last.lua" },
    { "lua", PROP.."open_row_damage.lua" },
    { "lua", PROP.."enter_attrib.lua" },
    { "lua", PROP.."cure_clear.lua" },
    { "lua", PROP.."enter_treasure.lua" },
    { "lua", PROP.."camp_learn_adventure.lua" },
    { "lua", PROP.."elect_sputtering.lua" },
    { "lua", PROP.."clear_bonus.lua" },
    { "lua", PROP.."bottles_effect.lua" },
    { "lua", PROP.."rob_attrib.lua" },
    { "lua", PROP.."reagent_cost.lua" },
    { "lua", PROP.."element_appear.lua" },
    { "lua", PROP.."curse_reduce_hp.lua" },
    { "lua", PROP.."department_defense.lua" },
    { "lua", PROP.."bank.lua" },
    { "lua", PROP.."tomb_attrib.lua" },
    { "lua", PROP.."treasure_heritage.lua" },
    { "lua", PROP.."cure_hp.lua" },
    { "lua", PROP.."disre_resist.lua" },
    { "lua", PROP.."skill_add_burn.lua" },
    { "lua", PROP.."camp_learn_magic.lua" },
    { "lua", PROP.."spell_add_migic.lua" },
    { "lua", PROP.."guard_attrib.lua" },
    { "lua", PROP.."sky_explore_scrap.lua" },
    { "lua", PROP.."sky_event.lua" },
    { "lua", PROP.."sky_strike_money.lua" },
    { "lua", PROP.."sky_temple.lua" },
    { "lua", PROP.."skill_add_spin.lua" },
    { "lua", PROP.."ignore_type.lua" },
    { "lua", PROP.."camp_magic.lua" },
    { "lua", PROP.."camp_max_mp.lua" },
    { "lua", PROP.."attrib3.lua" },
    { "lua", PROP.."material_down2.lua" },
    { "lua", PROP.."alchemist_time.lua" },
    { "lua", PROP.."alchemist_gold.lua" },
};

-- 开始预加载，每次加载耗时超过20ms就休息下
function startPreloadRes()
    cclog("开始预加载资源...");
    local index, total = 1, #list;
    local f = function()
        local now = socket.gettime();
        repeat
            if index > total then
                cclog("资源预加载完成。");
                list = {};
                ScheduleM.deleteScheme("PRELOAD_IN_LOGIN_UI");
                return;  
            end

            local info = list[index];
            if info[1] == "lua" then
                LOAD_RUN(info[2]);
            elseif info[1] == "module" then
                -- 访问下
                local _ = _G[info[2]];
            elseif info[1] == "scene" then
                require(info[2]);    
            elseif info[1] == "path" then
                local files = LOAD_PATH2(info[2]);
                for file, _ in pairs(files) do
                    if socket.gettime() - now > 0.02 then
                        return;
                    end
                    LOAD_RUN(info[2] .. "/" .. file);
                end
            end

            -- 下一个
            index = index + 1;
            if socket.gettime() - now > 0.02 then break end
        until false;
    end

    ScheduleM.createScheme("PRELOAD_IN_LOGIN_UI", f, 0.1, true);
end
